<template>
    <el-dialog :close-on-click-modal="false" append-to-body width="30%"  title="转派" :visible="show" :before-close="close">
        <div class="content">
            <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                <el-form-item label="选择人员" prop="sourceType">
                    <SelectByApi v-model="form.executor" :api="getPersonList" :params="{page:1,pageSize: 999}" :labelFiled="`memberName`" :valueFiled="`memberId`"></SelectByApi>
                </el-form-item>
            </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button @click="close">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
        </div>
    </el-dialog>
</template>
<script>
import {getPersonList} from '@/api/person'
import {recordDtl, surrogate} from '@/api/flow'



export default {
    props: {
        show: {
            type: Boolean,
            default: false
        },
        item: {
            type: Object,
            default:()=>{}
        }
    },
    watch: {
        show: {
            handler(nv) {
                if(nv) {
                    recordDtl({id: this.item.id}).then(res => {
                        const history = res.data.history;
                        this.ARG_TASK_ID = history[0].id;
                    })
                }
            },
            immediate: true
        }
    },
    data() {
        return {
            form: {},
            rules: {},
            ARG_TASK_ID: ''
        }
    },
    methods: {
        getPersonList,
        close() {
            this.$emit('update:show', false)
        },
        submit() {
            this.$refs['form'].validate(async valid => {
                if(valid) {
                    const form = {ARG_TASK_ID: this.ARG_TASK_ID, ARG_USER_SYSTEM: 1, ...this.form}
                    const res = await surrogate(form);
                    this.close()
                    this.$emit('confirm')
                }
            })
        }
    }
}
</script>